package com.heima.controller;


import com.heima.Result;
import com.heima.domain.po.HealthLecture;
import com.heima.domain.query.ResidentHealthLectureQuery;
import com.heima.service.IHealthLectureService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 健康讲座表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-07-28
 */
@Tag(name = "健康讲座接口")
@RestController
@RequestMapping("/health-lecture")
public class HealthLectureController {
    @Autowired
    private IHealthLectureService healthLectureService;
    @Operation(summary = "新增健康讲座")
    @PostMapping("/add")
    public Result add(@RequestBody HealthLecture healthLecture) {
        healthLecture.setCreateTime(LocalDateTime.now());
        healthLecture.setUpdateTime(LocalDateTime.now());
        healthLectureService.save(healthLecture);
        return Result.success();
    }
    @Operation(summary = "修改健康讲座")
    @PostMapping("/update")
    public Result update(@RequestBody HealthLecture healthLecture) {
        healthLectureService.updateById(healthLecture);
        return Result.success();
    }
    @Operation(summary = "根据id查询健康讲座")
    @GetMapping("/get/{id}")
    public Result get(@PathVariable Long id) {
        HealthLecture healthLecture = healthLectureService.getById(id);
        return Result.success(healthLecture);
    }
    @Operation(summary = "分页查询健康讲座")
    @GetMapping("/page")
    public Result page(ResidentHealthLectureQuery residentHealthLectureQuery) {
       return healthLectureService.findByPage(residentHealthLectureQuery);
    }

}

